package com.lgd.factoryattendance.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.lgd.factoryattendance.Bean.K3cloudBom;
import com.lgd.factoryattendance.R;

import java.util.ArrayList;
import java.util.List;

/**
 *  金蝶部装 网格布局 适配器
 * @Author lgd
 * @Date 2025/11/11 15:25
 */
public class AssemblyNameAdapter extends RecyclerView.Adapter<AssemblyNameAdapter.ViewHolder> {
    // 数据
    private List<K3cloudBom> mList;
    // 上下文
    private final Context context;
    // 定义一个接口
    private onRecyclerItemClickListener monRecyclerItemClickListener;

    public AssemblyNameAdapter(Context context, List<K3cloudBom> mList) {
        this.context = context;
        this.mList = mList != null ? mList : new ArrayList<>();
    }

    // 定义一个内部类ViewHolder
    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView tv_assembly_name;
        LinearLayout layout_assembly_name;
        public ViewHolder(@NonNull View view) {
            super(view);
            tv_assembly_name = (TextView)view.findViewById(R.id.tv_assembly_name);
            layout_assembly_name = (LinearLayout)view.findViewById(R.id.layout_assembly_name);
            layout_assembly_name.setOnClickListener(new View.OnClickListener(){
                @Override
                public void onClick(View v) {
                    if (monRecyclerItemClickListener != null){
                        monRecyclerItemClickListener.onRecyclerItemClick(getAdapterPosition());
                    }
                }
            });
        }
    }

    @NonNull
    @Override
    public AssemblyNameAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view =
                LayoutInflater.from(parent.getContext()).inflate(R.layout.assembly_name_bom,parent,false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull AssemblyNameAdapter.ViewHolder holder, int position) {
        K3cloudBom k3cloudBom = mList.get(position);
        holder.tv_assembly_name.setText(k3cloudBom.getAssemblyName());
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }


    public interface onRecyclerItemClickListener{     //自定义一个接口
        void onRecyclerItemClick(int position);
    }

    public void setMonRecyclerItemClickListener(onRecyclerItemClickListener listener) {
        monRecyclerItemClickListener = listener;
    }


}
